package package_1;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;



public class exercise_2 {
public static void main(String[] args) throws IOException {
	FileWriter fw = new FileWriter("worldcup.txt");
	BufferedWriter bW = new BufferedWriter(fw);
	bW.write("1998/法国"
			+"\n"+ "2002/巴西"
			+ "\n"+"2006意大利"
			+ "\n"+"2010/西班牙"
			+ "\n"+"2014/德国");
	bW.flush();
	fw.close();
	
	FileReader fr = new FileReader("worldcup.txt");
	BufferedReader br = new BufferedReader(fr);
	
	String line = br.readLine();
	while(line != null) {
		System.out.println(line);
		line = br.readLine();
	}
	fr.close();
	
	fr = new FileReader("worldcup.txt");
	br = new BufferedReader(fr);
	line = br.readLine();
	System.out.println(line);
	boolean found = false;
	System.out.println("please input year：");
	Scanner in = new Scanner(System.in);
	String year = in.next();
	while(line != null) {
		if(line.contains(year)) {
			System.out.println(line.substring(5));
			found = true;
			break;
		}
		else {
			line = br.readLine();
		}
	}
	fr.close();
	if(!found) {
		System.out.println("not found");
	}
}
}
